package org.enwey.icarenew.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import org.enwey.icarenew.Component.TopicItem;
import org.enwey.icarenew.Model.Topic;

import java.util.List;

/**
 * Created by enwey on 2014/11/20.
 */
public class TopicAdapter extends BaseAdapter {
    private List<Topic> mTopicList;
    private Context context;

    public TopicAdapter(Context context) {
        this.context = context;
    }
    public void setTopicList(List<Topic> list) {
        this.mTopicList = list;
    }
    @Override
    public int getCount() {
        return (mTopicList != null ? mTopicList.size() : 0);
    }

    @Override
    public Object getItem(int position) {
        return (mTopicList != null ? mTopicList.get(position) : null);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TopicItem topicItem = null;
        if (convertView == null) {
            topicItem = new TopicItem(context);
        }else {
            topicItem = (TopicItem) convertView;
        }

        topicItem.setTopicData(mTopicList.get(position));

        return topicItem;
    }
}
